/*

Copyright (C) 2010  Christoph Schnack 

    This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/

package VocabularyManagement;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

import GuiTools.*;
import Mainframe.Mainframe;
import Settings.*;
import Statistics.Statistics;
import Storage.*;
import VMAddManyWords.AddManyWords;
import VMCategoriesSettings.VMCategoriesSettings;
import VMTermClassSettingsDialog.*;

/**
 * 
 * Dialog for editing a vocabulary. 
 * 
 * @author Christoph Schnack
 */

public class EditVocDialog extends MDTribuitFrame{
	String[] alphSortedArray,alphSortedArrayInverse;
	JList sectionsList, tcList;
	CustomTextArea sizeLabel;
	JComboBox vocCB;
	JCheckBox filterCB,tcFilterCB,sectionFilterCB;
	HashMap<String,String[]> lectSortedHMInverse,lectSortedHM;
    MDTribuitFrame evdFrame;
    ListPanel LISTPANEL;;
    JPanel centerPanel;
    JButton evdAbortBtn;
    Vocabulary voc_to_edit;
    String[] lections;
    boolean inverse_selection;
    Settings SET;
    Language LANG;
    Storage MAINVOC;
    Mainframe MAINFRAME;
    MDManager VMDM;
    /**
     * 
     * @param arg is the to be edited vocabulary's name
     */
    public EditVocDialog(Storage mainvoc,Settings set,Mainframe mf,MDManager vmdm){
    	super(set.getLanguage().getEVDTitle(),vmdm);
    	evdFrame = this;
    	MAINVOC=mainvoc;
    	SET=set;
    	LANG=SET.getLanguage();
    	MAINFRAME=mf;
    	VMDM=vmdm;
		evdFrame.setName("evdFrame");
		inverse_selection = false;
		
		vocCB = new JComboBox();
		vocCB.setPreferredSize(new Dimension(200,26));
		
		String[] noWords = {LANG.getNoWordsAvailable()};
		LISTPANEL = new ListPanel(LANG.getNone(),noWords,noWords);
		
		evdAbortBtn = new JButton(LANG.getClose());
		evdAbortBtn.addActionListener(new evdAbortBtnListener());
		JPanel evdBtnPanel = new JPanel();
		evdBtnPanel.add(evdAbortBtn);
		evdBtnPanel.setBackground(GuiTools.BGCOLOR);

	//Informationen
		sizeLabel = new CustomTextArea("0");
		LabelPanel evdWordsPanel = new LabelPanel(LANG.getWords()+": ", sizeLabel);

		filterCB = new JCheckBox(LANG.getFilter(),false);
		filterCB.addActionListener(new EnableFilterCBListener());
		filterCB.setToolTipText(LANG.getToolTipTextFilterWordList());
	//termClass list	
		tcList = new JList(new Vector<String>());
		tcList.addListSelectionListener(new ListSelectionListener(){
			public void valueChanged(ListSelectionEvent arg0) {
				if(tcList.isEnabled()){
					setFilteredListData();
				}
			}
	    });
		CustomScrollPane tcListJSP = new CustomScrollPane(tcList);
		tcList.setEnabled(false);
		tcListJSP.setBorder(null);
		tcFilterCB = new JCheckBox(LANG.getTermclasses(),false);
		tcFilterCB.setToolTipText(LANG.getToolTipTextFilterTermClasses());
		tcFilterCB.setEnabled(false);
		tcFilterCB.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				tcList.setEnabled(tcFilterCB.isSelected());
				if(tcList.getSelectedValue()==null) tcList.setSelectedIndex(0);
				else setFilteredListData();
			}
		});
		
	//sections list
		sectionsList = new JList(new Vector<String>());
	    sectionsList.addListSelectionListener(new ListSelectionListener(){
			public void valueChanged(ListSelectionEvent arg0) {
				if(sectionsList.isEnabled()){
					setFilteredListData();
				}
			}
	    });
	    sectionsList.setEnabled(false);
		JScrollPane evdLectsJSP = new JScrollPane(sectionsList);
		evdLectsJSP.setBorder(null);
		sectionFilterCB = new JCheckBox(LANG.getSection(),false);
		sectionFilterCB.setToolTipText(LANG.getToolTipTextFilterSections());
		sectionFilterCB.setEnabled(false);
		sectionFilterCB.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sectionsList.setEnabled(sectionFilterCB.isSelected());
				if(sectionsList.getSelectedValue()==null) sectionsList.setSelectedIndex(0);
				else setFilteredListData();
			}
		});
		int 	firstHeight = (int)evdWordsPanel.getPreferredSize().getHeight(),
				cbHeight = (int)filterCB.getPreferredSize().getHeight(),
				x = 5;
		evdWordsPanel.setBounds(new Rectangle(evdWordsPanel.getPreferredSize()));
		evdWordsPanel.setLocation(x,0);
		
		filterCB.setBounds(new Rectangle(filterCB.getPreferredSize()));
		filterCB.setLocation(x,firstHeight+5);
		
		tcFilterCB.setBounds(new Rectangle(tcFilterCB.getPreferredSize()));
		tcFilterCB.setLocation(x,firstHeight+cbHeight+10);
		
		tcListJSP.setBounds(x,firstHeight+(2*cbHeight)+(15), 150,120);
		
		sectionFilterCB.setBounds(new Rectangle(sectionFilterCB.getPreferredSize()));
		sectionFilterCB.setLocation(x,firstHeight+(2*cbHeight)+120+20);
		
		evdLectsJSP.setBounds(x,firstHeight+(3*cbHeight)+120+25, 150,120);
		
		JPanel evdSidePanel = new JPanel();
		evdSidePanel.setLayout(null);
		evdSidePanel.add(evdWordsPanel);
		evdSidePanel.add(filterCB);
		evdSidePanel.add(tcFilterCB);
		evdSidePanel.add(tcListJSP);
		evdSidePanel.add(sectionFilterCB);
		evdSidePanel.add(evdLectsJSP);
		evdSidePanel.setBounds(0,0,170,400);
		
		JPanel vocCBPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,10,10));
		vocCBPanel.add(vocCB);
		vocCBPanel.setOpaque(false);
		JPanel headerPanel = new JPanel();
		headerPanel.setBackground(GuiTools.BGCOLOR);
		headerPanel.setLayout(new BorderLayout());
		headerPanel.add(BorderLayout.CENTER,new Header(LANG.getEVDTitle(),new Insets(15,15,0,15)));
		headerPanel.add(BorderLayout.SOUTH,vocCBPanel);
		
		GridBagConstraints tmpgbc = new GridBagConstraints();
		centerPanel = new JPanel();
		centerPanel.setLayout(new GridBagLayout());
		tmpgbc.fill = GridBagConstraints.BOTH;
		tmpgbc.anchor = GridBagConstraints.NORTHWEST;
		tmpgbc.insets = new Insets(5,5,5,5);
		centerPanel.add(LISTPANEL,tmpgbc);
		tmpgbc.gridx=1;
		centerPanel.add(evdSidePanel,tmpgbc);
		evdSidePanel.setPreferredSize(new Dimension(evdSidePanel.getPreferredSize().width,LISTPANEL.getPreferredSize().height+10));
		CustomScrollPane jsp = new CustomScrollPane(centerPanel);
		super.MENU = new EvdMenu();
		evdFrame.getContentPane().add(BorderLayout.NORTH,headerPanel);
		evdFrame.getContentPane().add(BorderLayout.CENTER,jsp);
		evdFrame.getContentPane().add(BorderLayout.SOUTH,evdBtnPanel);
		evdFrame.setJMenuBar(MENU);
		evdFrame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				if(MAINVOC.hasVocs()){
					SET.setEVDLastVocabulary((String)vocCB.getSelectedItem());
					SET.save();
				}
			}
		});
		setShortCuts();
		updateVocCB();
		evdFrame.setResizable(true);
		evdFrame.showUpAt(MAINFRAME);
		if(MAINVOC.hasVocs()){
			if(SET.getEVDLastVocabulary()!=null && !SET.getEVDLastVocabulary().equals("") && !SET.getEVDLastVocabulary().equals((String)vocCB.getSelectedItem())) vocCB.setSelectedItem(SET.getEVDLastVocabulary());
			else setVocabulary((String)vocCB.getSelectedItem());
		}
    }

    
    private void updateVocCB(){
    	vocCB.setEnabled(false);
    	if(vocCB.getItemListeners().length>0)vocCB.removeItemListener(vocCB.getItemListeners()[0]);
    	vocCB.removeAllItems();
    	if(MAINVOC.hasVocs()){
    		for(String s : MAINVOC.getNamen()) vocCB.addItem(s);
    		vocCB.setEnabled(true);
    		vocCB.addItemListener(new ItemListener(){
    			public void itemStateChanged(ItemEvent arg0) {
    				setVocabulary((String)vocCB.getSelectedItem());	
    			}
    		});
    		setVocabulary((String)vocCB.getSelectedItem());
    	}
    	else{
    		filterCB.setEnabled(false);
    		MENU.updateMenu();
    		LISTPANEL.updateData();
    	}
    }
    
    /**
     * Sets voc_to_edit, updates info panel and list data.
     *@author Christoph Schnack
     * @param voc
     */
    /*
	Is invoked whenever a vocabulary is edited. 
     */
    private void setVocabulary(String voc){
    	voc_to_edit = MAINVOC.getVocabulary(voc);
    	//deselect all filter
    	filterCB.setSelected(false);
    	tcFilterCB.setEnabled(false);
    	tcFilterCB.setSelected(false);
    	tcList.setEnabled(false);
		sectionFilterCB.setEnabled(false);
		sectionFilterCB.setSelected(false);
		sectionsList.setEnabled(false);
		
    	Vector<String> combinations = new Vector<String>();
    	MENU.updateMenu();
    	if(voc_to_edit.hasWords()){
    		//infoPanel
    		filterCB.setEnabled(true);
    		sizeLabel.setText(voc_to_edit.getWordList(true).length+"");
    		String combi;
			for(Word w : voc_to_edit.getWords()){
				combi = w.getTermclassA() + "-" + w.getTermclassB();
				if(!combinations.contains(combi))combinations.add(combi);
			}
			Collections.sort(combinations,String.CASE_INSENSITIVE_ORDER);
			tcList.setListData(combinations);
    		sectionsList.setListData(voc_to_edit.getLections());
    		
    		//listPanel
		    lectSortedHM = voc_to_edit.getSectionSortedAndIndexedHM(false);
		    lectSortedHMInverse = voc_to_edit.getSectionSortedAndIndexedHM(true);
		    alphSortedArray = GuiTools.sortAndIndexArray(voc_to_edit.getWordList(false));
			alphSortedArrayInverse = GuiTools.sortAndIndexArray(voc_to_edit.getWordList(true));
		}
    	else{
    		filterCB.setEnabled(false);
    		sizeLabel.setText("0");
    		tcList.setListData(combinations);
    		sectionsList.setListData(combinations);
    	}
    	LISTPANEL.updateData();
    	evdFrame.pack();
    }
    
    class EvdMenu extends TMenuBar{
    	JMenuItem sectsMI,tcMI,categoriesMI,addVocabularyMI,deleteVocabularyMI,editVocabularyNameMI,importMI,saveMI;
    	JMenu statMU;
    	public EvdMenu(){
    		JMenu settings = new JMenu(LANG.getVocabulary());
    		
    		addVocabularyMI = new JMenuItem(LANG.getNew());
    		addVocabularyMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				new AddVocDialog(evdFrame,MAINVOC,SET,MAINFRAME,VMDM);
    				updateVocCB();
    			}
    		});
    		
    		editVocabularyNameMI = new JMenuItem(LANG.getEditName());
    		editVocabularyNameMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				if(MAINFRAME.getMenu().getWordcheckRunning()){
    					JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
    					return;
    				}
    				new AddVocDialog(evdFrame,(String)vocCB.getSelectedItem(),MAINVOC,SET,MAINFRAME,VMDM);
    				updateVocCB();
    			}
    		});
    		
    		importMI = new JMenuItem(LANG.getImport());
    		importMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				new ImportVocabulary(SET,MAINVOC,MAINFRAME);
    			}
    		});
    		
    		saveMI = new JMenuItem(LANG.getSave());
    		saveMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				MAINVOC.saveVocabulary(MAINVOC.getVocabulary((String)vocCB.getSelectedItem()));
    			}
    		});
    		
    		deleteVocabularyMI = new JMenuItem(LANG.getDelete());
    		deleteVocabularyMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				if(MAINFRAME.getMenu().getWordcheckRunning()){
    					JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
    					return;
    				}
    				String to_delete = (String)vocCB.getSelectedItem();
    	    		if( JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(evdFrame,new JLabel(LANG.getDeleteReally()+": "+to_delete),LANG.getQuestion(), JOptionPane.YES_NO_OPTION)){
    	    			if(SET.getAutosave()){
    	    				if( JOptionPane.showConfirmDialog(evdFrame,new JLabel(LANG.getAutosaveActiveDeleteForever()),LANG.getQuestion(), JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE)!=JOptionPane.YES_OPTION) return;
    	    			}
    	    			if(SET.isVerbose()) System.out.println("deleting: "+to_delete);
    	    			MAINVOC.delVoc(to_delete);
    	    			MAINFRAME.updateMainframePane(MAINVOC,SET);
    	    			updateVocCB();
    	    		}
    			}
    		});
    		
    		tcMI = new JMenuItem(LANG.getTermclasses());
    		tcMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				if(MAINFRAME.getMenu().getWordcheckRunning()){
    					JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
    					return;
    				}
    				closeEVD();
    				new VocabularyTermClassManagement(voc_to_edit.getName(),MAINVOC,SET,MAINFRAME,VMDM);
    			}
    		});
    		sectsMI = new JMenuItem(LANG.getEditLections());
    		sectsMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				if(MAINFRAME.getMenu().getWordcheckRunning()){
    					JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
    					return;
    				}
    				closeEVD();
    				new EditLectionsDialog(voc_to_edit.getName(),MAINVOC,SET,MAINFRAME,VMDM);
    			}
    		});
    		categoriesMI = new JMenuItem(LANG.getCategories());
    		categoriesMI.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				if(MAINFRAME.getMenu().getWordcheckRunning()){
    					JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
    					return;
    				}
    				closeEVD();
    				new VMCategoriesSettings(voc_to_edit.getName(),MAINVOC,SET,MAINFRAME,VMDM);
    			}
    		});
    		JMenuItem rsSelectionMI = new JMenuItem(LANG.getSelection());
    		rsSelectionMI.addActionListener(new ResetSelectedStatisticsListener());
    		JMenuItem rsAllMI = new JMenuItem(LANG.getAll());
    		rsAllMI.addActionListener(new ResetAllStatisticsListener());
    		statMU = new JMenu(LANG.getResetStatistics());
    		statMU.add(rsSelectionMI);
    		statMU.add(rsAllMI);
    		settings.add(addVocabularyMI);
    		settings.add(editVocabularyNameMI);
    		settings.add(saveMI);
    		//FIXME add import to menu
    		//settings.add(importMI);
    		settings.add(deleteVocabularyMI);
    		settings.add(new JSeparator());
    		settings.add(sectsMI);
    		settings.add(tcMI);
    		settings.add(categoriesMI);
    		settings.add(statMU);
    		this.add(settings);
    	}
    	public void updateMenu(){
    		if(SET.getAutosave())saveMI.setEnabled(false);
    		else{
    			saveMI.setEnabled(MAINVOC.isChanged());
    		}
    		if(!MAINVOC.hasVocs()){
    			editVocabularyNameMI.setEnabled(false);
    			deleteVocabularyMI.setEnabled(false);
    			sectsMI.setEnabled(false);
    			tcMI.setEnabled(false);
    			categoriesMI.setEnabled(false);
    			statMU.setEnabled(false);
    		}
    		else{
    			editVocabularyNameMI.setEnabled(true);
    			deleteVocabularyMI.setEnabled(true);
    			tcMI.setEnabled(true);
    			categoriesMI.setEnabled(true);
	        	if(!voc_to_edit.hasWords()){
	        		statMU.setEnabled(false);
	        		sectsMI.setEnabled(false);
	        	}
	        	else{
	        		statMU.setEnabled(true);
	        		sectsMI.setEnabled(true);
	        	}
    		}
        }
    }
    
    class EnableFilterCBListener implements ActionListener{
    	public void actionPerformed(ActionEvent e){
    		JCheckBox cb = (JCheckBox) e.getSource();
			tcFilterCB.setEnabled(cb.isSelected());
			sectionFilterCB.setEnabled(cb.isSelected());
			tcList.setEnabled(tcFilterCB.isEnabled()&&tcFilterCB.isSelected());
			sectionsList.setEnabled(sectionFilterCB.isEnabled()&&sectionFilterCB.isSelected());
			setFilteredListData();
    	}
    }
    
    public void setFilteredListData(){
    	if(filterCB.isSelected()){
			Object[] tcSelectionsTmp = tcFilterCB.isSelected()?tcList.getSelectedValues():null,sectSelectionsTmp=sectionFilterCB.isSelected()?sectionsList.getSelectedValues():null;
			Vector<String> tcSelections = new Vector<String>(),sectionSelections=new Vector<String>(),collector = new Vector<String>(), collectorInverse = new Vector<String>();;
			if(tcSelectionsTmp!=null) for(Object s : tcSelectionsTmp) tcSelections.add((String)s);
			if(sectSelectionsTmp!=null) for(Object s : sectSelectionsTmp) sectionSelections.add((String)s);
			boolean tcsSelected = tcSelections.size()>0,sectsSelected = sectionSelections.size()>0;
			for(Word w : voc_to_edit.getWords()){
				if((tcsSelected?tcSelections.contains(w.getTermclassA()+"-"+w.getTermclassB()):true) && (sectsSelected?sectionSelections.contains(w.getLection()):true)){
					collector.add(w.getName());
					collectorInverse.add(w.getNameInverse());
				}
			}
			collector = GuiTools.sortAndIndexVector(collector);
			collectorInverse = GuiTools.sortAndIndexVector(collectorInverse);
			LISTPANEL.list.setListPanelData(LANG.getFiltered(), collector.toArray(new String[]{}), collectorInverse.toArray(new String[]{}));
    	}
    	else LISTPANEL.list.setListPanelData(LANG.getAll(),alphSortedArray,alphSortedArrayInverse);
    }
    
    class ResetSelectedStatisticsListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			resetStats(false);
		}
    }
    
    class ResetAllStatisticsListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			resetStats(true);
		}
    }
    
    public void resetStats(boolean all){
    	if(!all && LISTPANEL.list.isSelectionEmpty())JOptionPane.showMessageDialog(evdFrame,LANG.getNothingChosen());
		else{
			if(!new File(GuiTools.TRIBUITHOME+File.separator+"settings"+File.separator+"statistics.trib").exists())JOptionPane.showMessageDialog(evdFrame,LANG.getNoStatisticsAvailable());
			else{
				Statistics stat = MAINVOC.getStatistics();
				String name = voc_to_edit.getName();
				if(!all){
					Object[] selection = LISTPANEL.list.getSelectedValues();
					JPanel vocs = new JPanel();
					vocs.setLayout(new BoxLayout(vocs,BoxLayout.Y_AXIS));
					for(Object o : selection){
						String s = (String) o;
						if(s.contains("-")){
							vocs.add(new JLabel(s));
						}
					}
					int answer = JOptionPane.showConfirmDialog(evdFrame,vocs,LANG.getReallyDeleteStatisticsFor(),JOptionPane.YES_NO_OPTION);
					if(answer==JOptionPane.YES_OPTION){
						for(Object o : selection){
							String s = (String) o;
							if(s.contains("-")){
								stat.resetStatistic(name,s);
							}
						}
						stat.saveStatistics(false);
					}
				}
				else{
					int answer = JOptionPane.showConfirmDialog(evdFrame,LANG.getReallyDeleteAllStatistics(),LANG.getAttention(),JOptionPane.YES_NO_OPTION);
					if(answer==JOptionPane.YES_OPTION){
						stat.removeVocabularyStatistic(name);
						stat.saveStatistics(false);
					}
				}
			}
			
		}
    }


    class evdAbortBtnListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			closeEVD();
		}
    }
    
    /**
     * 
     * Creates a custom JPanel for Words in EditVocDialog.
     * Includes a TribuitTextField to search, RadioButtons to toggle between sortation and edit-Buttons
     * 
     * @author Christoph Schnack
     *
     */
    
    class ListPanel extends JPanel{
    	LPWordList list;
    	MiniButton addWordButton,addManyWordsButton,editWordButton,deleteWordButton;
    	/**
    	 * @param arg_array sorted and indexed array
    	 * @param arg_array_inverse sorted and indexed array
    	 */
    	public ListPanel(String title,String[] arg_array,String[] arg_array_inverse){
    		super();
    		list = new LPWordList(title,arg_array,arg_array_inverse);
    		
    	//Editierungsbuttons
    		addWordButton = new MiniButton(GuiTools.MINI_PLUS_ICON,GuiTools.MINI_PLUS_HOVERED_ICON,GuiTools.MINI_PLUS_DISABLED_ICON,true,new AddWordBtnListener());
    		addWordButton.setToolTipText(LANG.getToolTipAdd()+" (STRG + N)");
    		deleteWordButton = new MiniButton(GuiTools.MINI_MINUS_ICON,GuiTools.MINI_MINUS_HOVERED_ICON,GuiTools.MINI_MINUS_DISABLED_ICON,true,new DeleteWordBtnListener());
    		deleteWordButton.setToolTipText(LANG.getToolTipDel());
    		editWordButton = new MiniButton(GuiTools.MINI_EDIT_ICON,GuiTools.MINI_EDIT_HOVERED_ICON,GuiTools.MINI_EDIT_DISABLED_ICON,true,new EditWordBtnListener());
    		editWordButton.setToolTipText(LANG.getToolTipEdt() + " (STRG + E)");
    		addManyWordsButton = new MiniButton(GuiTools.MINI_MULTI_PLUS_ICON,GuiTools.MINI_MULTI_PLUS_HOVERED_ICON,GuiTools.MINI_MULTI_PLUS_DISABLED_ICON,true,new TAction(){
    			public void perform(){
    				if(MAINVOC.hasVocs()){
    					closeEVD();
	    				new AddManyWords(voc_to_edit.getName(),MAINVOC,SET,MAINFRAME,VMDM);
    				}
    			}
    		});
    		addManyWordsButton.setToolTipText(LANG.getAddVariousWords());
    		JPanel lpButtonPanel = new JPanel();
    		lpButtonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    		lpButtonPanel.add(addWordButton);
    		lpButtonPanel.add(addManyWordsButton);
    		lpButtonPanel.add(deleteWordButton);
    		lpButtonPanel.add(editWordButton);
    		lpButtonPanel.setBackground(Color.gray);
    		
    		JPanel lpAllListComponentsPanel = new JPanel();
    		lpAllListComponentsPanel.setLayout(new BoxLayout(lpAllListComponentsPanel,BoxLayout.Y_AXIS));
    		lpAllListComponentsPanel.add(list);
    		lpAllListComponentsPanel.add(lpButtonPanel);
    		
    		this.setBackground(Color.gray);
    		this.setLayout(new GridBagLayout());
    		GridBagConstraints lpGbc = new GridBagConstraints();
    		lpGbc.fill = GridBagConstraints.BOTH;
    		lpGbc.insets = new Insets(5,5,0,5);
    		lpGbc.weightx=1;
    		lpGbc.weighty = 2;
    		this.add(lpAllListComponentsPanel,lpGbc);
    		if(arg_array[0].equals(LANG.getNoWordsAvailable())){
    			deleteWordButton.setEnabled(false);
    			editWordButton.setEnabled(false);
    		}
    	}
    	
    	public void updateData(){
    		if(voc_to_edit!=null && MAINVOC.hasVocs()){
	    		list.setVocabularyNames(voc_to_edit.getNameA(),voc_to_edit.getNameB());
	    		addWordButton.setEnabled(true);
    			addManyWordsButton.setEnabled(true);
	    		if(!voc_to_edit.hasWords()){
	    			String[] noWords = {LANG.getNoWordsAvailable()};
	    			list.setListPanelData(LANG.getNone(), noWords,noWords);
	    			deleteWordButton.setEnabled(false);
	    			editWordButton.setEnabled(false);
	    		}
	    		else{
	    			deleteWordButton.setEnabled(true);
	    			editWordButton.setEnabled(true);
	    			list.setListPanelData(LANG.getAll(), alphSortedArray, alphSortedArrayInverse);
	    		}
    		}
    		else{
    			addWordButton.setEnabled(false);
    			addManyWordsButton.setEnabled(false);
    			deleteWordButton.setEnabled(false);
    			editWordButton.setEnabled(false);
    			String[] noWords = {LANG.getNoWordsAvailable()};
    			list.setListPanelData(LANG.getNone(), noWords,noWords);
    			list.setVocabularyNames("null", "null");
    		}
    	}
    	
    	public void clickNewWordButton(){
    		addWordButton.doClick();
    	}
    	
    	public void grabFocusList(){
    		if(list.isSelectionEmpty()) list.setSelectedIndex(0);
    		list.grabFocusList();
    	}
    	
    	public void grabFocusTF(){
    		list.tfGrabFocus();
    	}
    	
    	public void selectLangA(){
    		list.clickLangABtn();
    	}
    	
    	public void selectLangB(){
    		list.clickLangBBtn();
    	}
    	
    	public void clickEditBtn(){
    		editWordButton.doClick();
    	}
    	
    	class AddWordBtnListener implements TAction{
			public void perform(){
				closeEVD();
				new EditWordDialog(voc_to_edit.getName(),MAINVOC,SET,MAINFRAME,VMDM);
			}
	    }
    	
	    class DeleteWordBtnListener implements TAction{
			public void perform(){
				Object[] selected = list.getSelectedValues();
				if(selected.length==0){
					JOptionPane.showMessageDialog(evdFrame,LANG.getNothingChosen());
					return;
				}
				else{
					if(MAINFRAME.getMenu().getWordcheckRunning()){
						JOptionPane.showMessageDialog(evdFrame, LANG.getQuitWordcheckBeforeAlteringWordData(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
						return;
					}
					String[] selection = new String[selected.length];
					int r = 0;
					for(Object o: selected){
						selection[r++]=(String) o;
					}
					JPanel panel = new JPanel();
					panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
					int realWords=0;
					for(String to_delete : selection){
						if(to_delete.contains("-")){
							panel.add(new JLabel(to_delete));
							realWords++;
						}
						else JOptionPane.showMessageDialog(evdFrame,LANG.getNotDeletable()+": "+to_delete);
					}
					JScrollPane jsp = new JScrollPane(panel);
					jsp.setPreferredSize(new Dimension(300,200));
					if(realWords>0){
						int answer = JOptionPane.showConfirmDialog(evdFrame,jsp,LANG.getDeleteReally()+" ?",JOptionPane.YES_NO_OPTION);
						if(answer==JOptionPane.YES_OPTION){
							boolean oldAutosave = SET.getAutosave();
							SET.setAutosave(false);
							for(String toDelete : selection){
								if(toDelete.contains("-")){
									if(list.isInverse()) toDelete = voc_to_edit.getWordByNameInverse(toDelete).getName();
									MAINVOC.deleteWord(voc_to_edit.getName(),toDelete);
								}
							}
							SET.setAutosave(oldAutosave);
							MAINVOC.saveVocabularyIfAutosave(voc_to_edit);
							MAINFRAME.updateMainframePane(MAINVOC,SET);
							setVocabulary((String)vocCB.getSelectedItem());
						}
					}
				}
			}
	    }

	    class EditWordBtnListener implements TAction{
			public void perform(){
				String ts = (String) list.getSelectedValue();
				if(ts==null)JOptionPane.showMessageDialog(evdFrame,LANG.getNothingChosen());
				else{
					if(ts.contains("-")){
						closeEVD();
						new EditWordDialog(voc_to_edit.getName(),(!list.isInverse())? voc_to_edit.getWordByName(ts): voc_to_edit.getWordByNameInverse(ts),MAINVOC,SET,MAINFRAME,VMDM);
					}
					else JOptionPane.showMessageDialog(evdFrame,LANG.getNotEditable());
				}
			}
	    }
	    
	    class LPWordList extends WordList{
	    	public LPWordList(String title,String[] arg_array,String[] arg_array_inverse){
	    		super(SET,title,"null","null",arg_array,arg_array_inverse);
	    		lpLang1RB.setToolTipText(LANG.getToolTipTextSortListByLanguageA());
	    		lpLang2RB.setToolTipText(LANG.getToolTipTextSortListByLanguageB());
	    	}
	    	public void mouseClick(){
		    	String ts = (String) list.getSelectedValue();
				if(ts==null)JOptionPane.showMessageDialog(evdFrame,LANG.getNothingChosen());
				else{
					if(ts.contains("-")){
						closeEVD();
						new EditWordDialog(voc_to_edit.getName(),(!list.isInverse())? voc_to_edit.getWordByName(ts): voc_to_edit.getWordByNameInverse(ts),MAINVOC,SET,MAINFRAME,VMDM);
					}
					else JOptionPane.showMessageDialog(evdFrame,LANG.getNotEditable());
				}
		    }
	    }
    }
    
    private void closeEVD(){
    	if(MAINVOC.hasVocs()){
			SET.setEVDLastVocabulary((String)vocCB.getSelectedItem());
			SET.save();
		}
		evdFrame.dispose();
    }
    
    private void setShortCuts(){
    	InputMap inputMap = centerPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    	ActionMap actionMap = centerPanel.getActionMap();
    	
    	inputMap.put(KeyStroke.getKeyStroke("ctrl X"), "close");
		actionMap.put("close", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				evdAbortBtn.doClick();
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl L"), "focusList");
		actionMap.put("focusList", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.grabFocusList();
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl F"), "focusTF");
		actionMap.put("focusTF", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.grabFocusTF();
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl E"), "editWord");
		actionMap.put("editWord", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.clickEditBtn();
			}
		});
    	inputMap.put(KeyStroke.getKeyStroke("ctrl N"), "newWord");
		actionMap.put("newWord", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.clickNewWordButton();
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl I"), "activateFilter");
		actionMap.put("activateFilter", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				if(filterCB.isEnabled()){
					filterCB.doClick();
				}
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl S"), "activateSectionFilter");
		actionMap.put("activateSectionFilter", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				if(filterCB.isEnabled()){
					sectionFilterCB.doClick();
					if(sectionFilterCB.isSelected()) sectionsList.grabFocus();
				}
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("ctrl T"), "activateTCFilter");
		actionMap.put("activateTCFilter", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				if(filterCB.isEnabled()){
					tcFilterCB.doClick();
					if(tcFilterCB.isSelected()) tcList.grabFocus();
				}
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("alt UP"), "tcUp");
		actionMap.put("tcUp", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				if(vocCB.isEnabled()){
					if(vocCB.getSelectedIndex()>0) vocCB.setSelectedIndex(vocCB.getSelectedIndex()-1);
				}
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("alt DOWN"), "tcDown");
		actionMap.put("tcDown", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				if(vocCB.isEnabled()){
					if(vocCB.getSelectedIndex()<vocCB.getItemCount()-1) vocCB.setSelectedIndex(vocCB.getSelectedIndex()+1);
				}
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("alt LEFT"), "langA");
		actionMap.put("langA", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.selectLangA();
			}
		});
		inputMap.put(KeyStroke.getKeyStroke("alt RIGHT"), "langB");
		actionMap.put("langB", new AbstractAction(){
			public void actionPerformed(ActionEvent e){
				LISTPANEL.selectLangB();
			}
		});
    }
}//EditVocDialog